package com.example.demo.controller;


import com.sun.jna.Library;
import com.sun.jna.Native;
import org.springframework.web.bind.annotation.*;

/**
 * TODO：JNA 操作dll动态库
 */
@RestController
@RequestMapping("test/")
public class JnaExample {

    public interface DevCapture extends Library {
        DevCapture INSTANCE = Native.load("lib/DevCapture", DevCapture.class);

        /**
         * 函数功能：拍照
         * 参数一：图像保存路径
         * 参数二：是否条码识别
         * 返回值：图像路径
         *
         * @param a
         * @param b
         * @return
         */
        String CaptureFromPreview(String a, int b);

        int CloseDevice();

        void SetRotateAngle(int angle);

        int OpenDevice();

        int ReadCard();

        int OpenDevice(int index, int width, int height, String mhwnd, Boolean isDisplay);

        int GetDeviceCount();

        int GetStillResolutionCount(int index);
    }

    @GetMapping(value = "resolution")
    public void GetStillResolutionCount() {
        int index = DevCapture.INSTANCE.GetStillResolutionCount(0);
        System.out.println("分辨率数目：" + index);
    }

    @GetMapping(value = "count")
    public void getDeviceCount() {
        int result = DevCapture.INSTANCE.GetDeviceCount();
        System.out.println("数量: " + result);
    }

    @GetMapping(value = "open")
    public void open() {
        int result = DevCapture.INSTANCE.OpenDevice(1, 2, 3, null, true);
        System.out.println("打开: " + result);
    }

    @GetMapping(value = "device")
    public void device() {
        String date = DevCapture.INSTANCE.CaptureFromPreview("D:\\test", 1);
        System.out.println("拍照：" + date);
    }

    @GetMapping(value = "close")
    public void close() {
        int close = DevCapture.INSTANCE.CloseDevice();
        System.out.println("关闭：" + close);

    }

    public static void main(String[] args) {
        int result = DevCapture.INSTANCE.GetDeviceCount();
        System.out.println("结果: " + result);
    }

}
